//引入express模块
const express=require('express')
const cors=require('cors')
//引入路由
const userRouter=require('./router/user.js')
const productRouter=require('./router/products')
const orderRouter=require('./router/order')
//创建服务器
const app=express()
app.use(cors())
//设置服务器端口
app.listen(3000,()=>{
  console.log('server is running on port 3000');
})
app.use(express.static('./public'))
app.use(express.urlencoded({
  extended:true
}))
app.use('/v1/users',userRouter)
app.use('/v1/products',productRouter)
app.use('/v1/orders',orderRouter)
app.use((err,req,res,next)=>{
  if(err){
    console.log(err);
  }
  res.send({code:500,msg:'服务器端错误'})
})
